ham=4 -- ham=4 (ham6); ham=6 (ham8)
function DIV(a,b)
  return(a-a%b)/b
  end
function ABS(a)
  if a<0 then
    a=(a*-1.0)
    end
  return(a)
  end
function INT(a)
  return(a-a%1)
  end
for y=0,height-1,1 do
  ro=0;go=0;bo=0;pf=0;zo=0
  for x=0,width-1,1 do
    r,g,b=get_rgb(x,y)
    w=((b*11)+(r*30)+(g*59))/100
    r=r*255;g=g*255;b=b*255
    r2=r;g2=g;b2=b
    if ham==4 then
      b2=(INT(b/16))*255/15
      g2=(INT(g/16))*255/15
      r2=(INT(r/16))*255/15
      w2=(INT(w/16))*255/15
      end
    if ham==6 then
      b2=(INT(b/4))*255/63
      g2=(INT(g/4))*255/63
      r2=(INT(r/4))*255/63
      w2=(INT(w/4))*255/63
      end
    bd=ABS(b2-bo)
    rd=ABS(r2-ro)
    gd=ABS(g2-go)
    tg=0
    if bd>=rd and bd>=gd and tg==0 then
      bo=b2;pf=1;zo=bo;tg=1
      end
    if rd>=bd and rd>=gd and tg==0 then
      ro=r2;pf=2;zo=ro;tg=1
      end
    if gd>=rd and gd>=bd and tg==0 then
      go=g2;pf=3;zo=go;tg=1
      end
    set_rgb(x,y,ro/255,go/255,bo/255)
    end
  progress(y/height)
  end

